package com.gnerv.rabbitmq.agent.dispatch;

import com.gnerv.rabbitmq.agent.command.RabbitmqDiagnosticsCommand;
import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import org.springframework.stereotype.Service;

/**
 * @author Gnerv LiGen
 */
@Service
public class BaseDispatchService {

    public String version(Node node) {
        ExecTools.ExecResult serverVersion = RabbitmqDiagnosticsCommand.build(node).serverVersion(node.getName());
        int status = serverVersion.getStatus();
        if (status == 0) {
            return serverVersion.getStdout().trim();
        }
        throw new RuntimeException("无法获取节点版本");
    }

}
